const ele = require('electron');
const ses = ele.session;
const rs = require('./log');
const brow = ele.BrowserWindow;
module.exports = {
    getToken: function () {
        ses.defaultSession.cookies.get({
            domain: '.alimama.com'
        }, function (error, cookies) {
            if (error == null) {
                var tk_cookie = {};
                var bstop = false;
                for (var i = 0; i < cookies.length; i++) {
                    tk_cookie[cookies[i].name] = cookies[i].value;
                    if (cookies[i].name.search('cookie') != '-1') {
                        global.tk_is_login=true;
                        bstop =true;
                    }
                }
                if (bstop) {
                    global.cookies.tk_cookie=tk_cookie;
                    rs.createLog(tk_cookie);
                    if (global.childWindow) {
                        var loginBrow = brow.fromId(global.childWindow);
                        loginBrow.close();
                    }

                }
            }
        });

    }
};